package com.demo.java.controller;

import com.demo.java.model.params.Query;
import com.demo.java.model.params.Res;
import com.demo.java.service.BeanService;
import com.demo.java.util.LogUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@Slf4j
@RestController
@RequestMapping("/api/v1/bean")
public class BeanController implements ApplicationContextAware {

    @Autowired
    private BeanService beanService;

    @RequestMapping(value = "/run", method = {RequestMethod.GET, RequestMethod.POST})
    public Object get(@RequestBody Query query) {
        beanService.run();
        return Res.ok("success");
    }

    @Override
    public void setApplicationContext(ApplicationContext app) throws BeansException {
        log.info("=====|> bean type: " + app.getEnvironment().getProperty("bean.type"));

    }
}
